const express = require('express');
const request = require('request');
const session = require('express-session')
const router = express.Router();
/* GET query page. */
router.get('/', function(req, res, next) {
    if(req.session.logged){
        const url = 'http://result:5000/result'
        // const url = 'http://localhost:5000/result'
        body = {"uid": req.session.uid}
        console.log(body)
        request({
            url: url,
            method: "POST",
            json: true,
            body: JSON.stringify(body)
        }, function(error, response, body){
            if(!error && response.statusCode == 200){
                console.log(body)
                res.send(body)
                
            }
            else
            {
                res.send('Error, try again')
            }

        });


    }
    else {
        res.redirect('/signin')
    }
  
});

module.exports = router;